// pages/groups/group/group.js

Page({

    /**
     * 页面的初始数据
     */
    data: {
        gName: '',
        gId: 0,
        uId: 0,
        uName: '',
        list: [],
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        console.log('onload');

        var that = this;
        this.setData({
            gId: options.gId,
            gName: options.gName,
            uId: options.uId
        })
        wx.request({
            url: 'http://127.0.0.1:8080/superadmin/getuserbyid',
            data: {
                userId: that.data.uId
            },
            method: 'GET',
            success: function (res) {
                var uName = res.data.user.uName;
                that.setData({
                    uName: uName
                })
            }

        })
        console.log(that.data.uName);
        // console.log(that.data.gId);
        // console.log(that.data.gName);
        // console.log(that.data.uId);
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {
        console.log('onready');
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        console.log('group.js的onshow');
        var that = this;
        wx.request({
            url: 'http://127.0.0.1:8080/superadmin/memberaccountlist',
            data: {
                gId: that.data.gId
            },
            method: 'GET',
            success: function (res) {
                var list = res.data.memberaccountlist;
                that.setData({
                    list: list
                })
            }
        })
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    },
    quit: function (e) {
        var that = this;
        wx.showModal({
            title: '退群',
            content: '确定要退出该群？',
            showCancel: true,
            cancelColor: 'cancelColor',
            success: function (res) {
                if (res.confirm) {
                    wx.request({
                        url: 'http://127.0.0.1:8080/superadmin/quitgroup',
                        data: {
                            uId: that.data.uId,
                            gId: that.data.gId
                            
                        },
                        method: 'GET',
                        success: function (res) {
                            wx.showToast({
                                title: '退群成功',
                                icon: 'none',
                                duration: 1000,
                            })
                            wx.switchTab({
                                url: '/pages/groups/groups',
                            })
                        }
                    })

                }
            }
        })
    },
    issue: function () {
        var that = this;
        wx.navigateTo({
            url: '/pages/groups/group/issue/issue?gId=' + that.data.gId+'&uId='+that.data.uId,
        })
    },
    pay: function () {
        var that = this;
        wx.navigateTo({
            url: '/pages/groups/group/pay/pay?gId=' + that.data.gId+'&uId='+that.data.uId,
        })
    },
    groupaccount: function () {
        var that = this;
        console.log("gid:" + that.data.gid);
        wx.navigateTo({
            url: '/pages/groups/group/group_account/group_account?gId=' + that.data.gId,
        })

    }
})